package com.kuangstudy.alipay.pwd;

import com.alibaba.fastjson.JSONObject;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.EnvironmentPBEConfig;
import org.junit.Test;

public class JasyptTest {

    @Test
    public void test(){
        String jsonstr = "{\"orderNumber\":\"2021033000493301\",\"money\":\"1\",\"userId\":1}";
        JSONObject jsonObject = JSONObject.parseObject(jsonstr);
        System.out.println(jsonObject.getString("money"));
        System.out.println(jsonObject.getString("userId"));
    }
    
    
    @Test
    public void testEncrypt() throws Exception {
        StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
        EnvironmentPBEConfig config = new EnvironmentPBEConfig();

        config.setAlgorithm("PBEWithMD5AndDES");          // 加密的算法，这个算法是默认的
        config.setPassword("kuangstudy123224.");                        // 加密的密钥，随便自己填写，很重要千万不要告诉别人
        standardPBEStringEncryptor.setConfig(config);
        System.out.println(standardPBEStringEncryptor.encrypt("xuexiangban"));
        System.out.println(standardPBEStringEncryptor.encrypt("yzEK5p7TGNNw5nNj"));
        System.out.println(standardPBEStringEncryptor.encrypt("MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCDOuy30XrqzQUkM1DgxpJ7BXJY/505/19Xk/nB6GPsbw36334GKH+HqkCC4+V/XJ3hVL7PUOUci5I/87uubvTUlTL8x6Vz6C2Qa58POHHmtUjAX1t3oIjquyhHyUI0R+9AOC4UhmITgDiCnqXhb5HWhzOltRE9fezq9gMIjUi45KoxBMeAsA5MqohnWLb4QTGbd5+AS0Y5s7p1EPo2K+ZAIdGNg7nATGGXVKymSsFjPr1kKyEcJ4BjBwpZLzugr42htz6RlpdmAoXuCwCwSnrURjHfM2ksugJhMB/RRCcC3fzvAfAqKutgcOv7VK7BuU4w+vaOwq6WbHqb59eA1BhRAgMBAAECggEAVEhE/m4I3sKcObrHiAWg0GgYH7bT2Qr9xfag4vwJKTHOLcDaZMQf3BbpZedOXzUxpSXTgrz22RV+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YfafTs4acviqUayHyCwQuiQ3DKOyGkpoaQiIwmmLUUSioi10A10RXlteQ="));
    }

    @Test
    public void testDe() throws Exception {
        StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
        EnvironmentPBEConfig config = new EnvironmentPBEConfig();

        config.setAlgorithm("PBEWithMD5AndDES");
        config.setPassword("kuangstudy123224.");
        standardPBEStringEncryptor.setConfig(config);
        String encryptedText = "QJvKGb2ByUgjO7GAXTcGTEv7MQQUlRsL+6eh/EUuu1UlBPHvmmKrdR00OVb3SEuEvD8KDmtQcpxvDmlyxpbZFQ==";   //加密后的密码
        String plainText = standardPBEStringEncryptor.decrypt(encryptedText);
        System.out.println(plainText);
    }

}